<?php

namespace App\Http\Controllers\Home;
//引入专业类
use App\Http\Models\Profession;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;



class IndexController extends Controller
{
    //首页展示
//    public function index(Request $request,Profession $profession = null){//默认情况下(没有传入专业id) 取出php的课程信息
//        $pro_info = Profession::get();
//        //判断是否有传值 没有传值 则默认取出id为2的数据
//        $profession = $profession->pro_name==null?Profession::find(2):$profession;
//        //专业根据关联关系 获取课程
//        $course_info = $profession->course;
//        return view('home.index.index',compact('pro_info','course_info'));
//    }
    //渴求时加载
    public function index(Request $request,$id=2){
//        dd($pro_info);
        $pro_info = Profession::pluck('pro_name','pro_id');
        //渴求时加载
        $course_info = Profession::with(['course'=>function($c){
            $c->with(['lesson'=>function($c){
                $c->with('teacher');
            }]);
        }])->find($id)->toArray();
//        dd($course_info);
        return view('home.index.indexWith',compact('pro_info','course_info'));
    }
}
